//import { from } from 'form-data'
import { bbsDetail,bbsDetailList} from '../../../api/hot'
const app = getApp().globalData
import {applyTask} from '../../../api/apply'
//import { sale_list } from '../../../api/index'
Page({
  data: {
    baseId: 0,
    p:{
      baseId: 0,
      applyContent:''
    },
    q: {
      title: '咨询名称',
      content: '咨询内容',
      other: '图片',
      startTime: '2022-02-02 02:02:02',
      avatar: '头像',
      applyName: '咨询人',
      deptName: "财政所"
    },
    showSelTime: false,
    chatlist: [{ uid: 1 }, { uid: 2 }, { uid: 3 }],
    message: '',
    isSay: 1,
  },
  onLoad(e) {
    this.setData({
      isSay:e.is,
      baseId:e.id
    })
    console.log(e);
    console.log(this.data.isSay);
    this.baseId=e.id;
    bbsDetail(e.id).then((res) => {
      this.setData({
        q: res.datas,      
      })
    }),
   this.getList()    
  },
  onShow() {
    this.getList()  
  },
  bindinput(e) {
    this.setData({ message: e.detail.value })
  },
  refCurMessage(){
    this.getList()
  },
  sendCurMessage() {
    const p = {
      ...this.data.p, 
      baseId: this.data.baseId,
      applyContent: this.data.message
    }
    console.log(p);
    applyTask(p).then((res) => {

      console.log(res);
      wx.showToast({
          icon: 'success',
          title: res.datas
      })
      this.getList();
      this.data.page = 1
      this.data.finished = false
      this.setData({ message: '' })
    })
    // addPl({ type: 4, CommentContent: this.data.message }).then((res) => {
    //   wx.showToast({
    //       icon: 'success',
    //       title: res.message
    //   })
    //   this.data.page = 1
    //   this.data.finished = false
    //   this.setData({ message: '' })
    // })
  },
  showPop() {
    this.setData({ showSelTime: true })
  },
  closePop() {
    this.setData({ showSelTime: false })
  },
  preview(e) {
    let cur = e.currentTarget.dataset.cur
    let imgs = e.currentTarget.dataset.obj
    let pics = []
    imgs.forEach((it) => {
      pics.push(it.split('?')[0])
    })
    wx.previewImage({
      urls: pics,
      current: cur.split('?')[0]
    })
  },
  getList() {
    console.log('获取bbs详情列表'+this.baseId);
    //bbsDetailList({page: this.data.page, limit: 20, id: this.baseId}).then(
    bbsDetailList(this.baseId).then((res) => {
      wx.stopPullDownRefresh()
      console.log(res.datas)
      this.setData({
        formMark: true,
        chatlist:res.datas
        //chatlist: this.data.page > 1 ? this.data.list.concat(res.datas) : res.datas
        
      })
      if (this.data.chatlist.length >= res.total) {
        this.data.finished = true
      }
      console.log(this.data.chatlist);
    })
  },
  onPullDownRefresh() {
    this.data.finished = false
    this.data.page = 1
    this.getList()
  },
  onReachBottom() {
    if (this.data.finished) {
      return
    }
    this.data.page++
    this.getList()
  },
  gopage(e) {
    const { url } = e.currentTarget.dataset
    wx.navigateTo({ url })
  }
})